<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 14-11-9
 * Time: 下午9:25
 */
 
  $request_data = file_get_contents("php://input");
//echo $request_data;
//exit;
 if (empty($request_data)) {
     exit('empty request data');
 }
 $json_array = json_decode($request_data);
 $xml = base64_decode($json_array->data);
echo $xml;exit;
 $xml_arr = simplexml_load_string($xml);
 print_r($xml_arr);
 $header = $xml_arr->header;
 $body   = $xml_arr->body;
 $pid = (string)$body->resourceId;
exit;
    $pdo = new PDO('mysql:dbname=myuu;host=127.0.0.1;port=3306', 'admin', 'adm*753951');
    $pdo->exec("SET NAMES 'utf8';");
    $sql = "SELECT l.id as lid,l.p_type,l.title as ltitle,l.area,l.address,l.attribute,l.jtype,l.jqts,l.bhjq,l.jtzn,l.opentime,l.tel,";
    $sql.="f.tourist_info,t.title as ttitle,t.status,t.getaddr,t.pay,t.storage,f.rdays,t.delaydays,t.ddays,f.dhour,t.reb,t.buy_limit_low,";
    $sql.="t.buy_limit_up,l.imgpath,t.tprice,l.uptime";
    $sql.=" FROM uu_products p LEFT JOIN  uu_jq_ticket t on p.id=t.pid";
    $sql.=" LEFT JOIN uu_land l ON p.contact_id=l.id LEFT JOIN uu_land_f f ON l.id=f.lid";
    $sql.=" WHERE p.id=? limit 1";
try{
    $stmt = $pdo->prepare($sql);
//    $pid = $_GET['pid'];
//    $pid = (int)$body->resourceId;
    $stmt->execute(array($pid));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    // print_r($row1);
    // $tid = $row1['id'];
    // $sql = "select contact_id from uu_products where id=?";
    // $stmt = $pdo->prepare($sql);
    // $pid = $_GET['pid'];
    // $stmt->execute(array($pid));
    // $row2 = $stmt->fetch(PDO::FETCH_ASSOC);
    // $lid = $row2['contact_id'];
   // print_r($row2);
    // exit;
    // $sql = "select id,p_type,title,area,address,attribute,jtype,jqts,bhjq,jtzn,opentime,tel,delaytime,imgpath,uptime from uu_land where id=?";
    // $stmt = $pdo->prepare($sql);
    // $stmt->execute(array($lid));
    // $row3 = $stmt->fetch(PDO::FETCH_ASSOC);
    // print_r($row3);
    // $sql = "select tourist_info,rdays,dhour from uu_land_f where lid=?";
    // $stmt = $pdo->prepare($sql);
    // $stmt->execute(array($lid));
    // $row4 = $stmt->fetch(PDO::FETCH_ASSOC);   
    // print_r($row);
    // exit;
    
    
$xxxml = '<?xml version="1.0" encoding="UTF-8"?>
                <response xsi:schemaLocation="http://open.12301.cc/2014/ResponseSchema ResponseDataSchema-2.3.0.xsd" xmlns="http://open.12301.cc/2014/ResponseSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <header>
                    <application>PFT.API.Agent</application>
                    <processor>PFTDataExchange</processor>
                    <version>v2.3.0</version>
                    <bodyType>PFTProductCatchResponseBody</bodyType>
                    <account>String</account>
                    <verifycode>String</verifycode>		
                </header>
                <body xsi:type="PFTProductCatchResponseBody">';
$xxxml .= "
                    <product_id>$pid</product_id>
                    <account>94</account>
                    <product_type>".$row['p_type']."</product_type>
                    <product_name>".$row['ltitle']."</product_name>
                    <city>".$row['area']."</city>
                    <address>".$row['address']."<address>
                    <include_ticket>";
$attr = json_decode($row['attribute']);
for($i=0;$i<count($attr);$i++){
    $xxxml .="    <ticket>
                            <id>".$attr[$i]->pid."</id>
                            <num>".$attr[$i]->num."</num>
                        </ticket>";
}
$startendcity = explode('|',$row['runtime']);
$start_city = $startendcity[0];
$end_city = $startendcity[1];
$rdays = $row['rdays']=="0"?"1":$row['rdays'];
$xxxml .="   </include_ticket>
                    <product_level>".$row['jtype']."</product_level>
                    <notice>".$row['jqts']."</notice>
                    <details>".$row['bhjq']."</details>
                    <traffic>".$row['jtzn']."</traffic>
                    <opentime>".$row['opentime']."</opentime>
                    <tel>".$row['tel']."</tel>
                    <use_delay_minute></use_delay_minute>
                    <start_city>$start_city</start_city>
                    <end_city>$end_city</end_city>
                    <tourist_inf>".$row['tourist_info']."</tourist_inf>
                    <journey_days>$rdays</journey_days>
                    <ass_stations>";
if($row['ass_stations']){
$ass_station = unserialize($row['ass_stations']);
echo $ass_station;
foreach($ass_station as $v){
$xxxml .="   <ass_station>
                        <assembling_place>".$v."</assembling_place>
                        <assembling_time>0</assembling_time>
                        <guide_telphone>0</guide_telphone>
                    </ass_station>";
}}else{
$xxxml .="   <ass_station>
                        <assembling_place></assembling_place>
                        <assembling_time></assembling_time>
                        <guide_telphone></guide_telphone>
                    </ass_station>";
}
$xxxml .="   </ass_stations>
                    <series_model></series_model>
                    <ticket_name>".$row['ttitle']."</ticket_name>
                    <status>".$row['status']."</status>
                    <get_ticket_info>".$row['getaddr']."</get_ticket_info>
                    <payment_type>".$row['pay']."</payment_type>
                    <total_storage>".$row['storage']."</total_storage>
                    <auto_cancel_minute></auto_cancel_minute>
                    <use_delay_type></use_delay_type>
                    <use_delay_days>".$row['delaydays']."</use_delay_days>
                    <use_deadline></use_deadline>
                    <book_early_days>".$row['ddays']."</book_early_days>
                    <book_deadline>".$row['dhour']."</book_deadline>
                    <refundcharge>".$row['reb']."</refundcharge>
                    <idcard_verify>0</idcard_verify>
                    <buy_min_num>".$row['buy_limit_low']."</buy_min_num>
                    <buy_max_num>".$row['buy_limit_up']."</buy_max_num>
                    <img_path>".$row['imgpath']."</img_path>
                    <verify_start_time></verify_start_time>
                    <verify_end_time></verify_end_time>
                    <market_price>".$row['tprice']."</market_price>
                    <update_time>".$row['uptime']."</update_time>
                    <price_array>
                    <price>
                        <price_id>".rand(0,100)."</price_id>
                        <start_date>".rand(2013,2014)."-".rand(1,12)."-".rand(1,28)."</start_date>
                        <end_date>".date("Y-m-d",strtotime("+5days"))."</end_date>
                        <valid_week>0,1,2,3,4</valid_week>
                        <storage>-1</storage>
                        <supply_price>".rand(1,100)."</supply_price>
                        <retail_price>".rand(101,200)."</retail_price>
                        <ptype>0</ptype>
                    </price>
                    <price>
                        <price_id>".rand(0,100)."</price_id>
                        <start_date>".rand(2013,2014)."-".rand(1,12)."-".rand(1,28)."</start_date>
                        <end_date>".date("Y-m-d",strtotime("+10days"))."</end_date>
                        <valid_week>5,6</valid_week>
                        <storage>-1</storage>
                        <supply_price>".rand(1,100)."</supply_price>
                        <retail_price>".rand(101,200)."</retail_price>
                        <ptype>0</ptype>
                    </price>";			
$xxxml .="   </price_array>
                </body>
                </response>";
}
catch(PDOException $e){
	$pdo->rollBack();
	echo $e->getMessage();
}
print_r($xxxml);


